﻿namespace EventbriteTests
{
    using System;
    using System.Linq;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using EventbriteApi.Model;

    [TestClass]
    public class EventbriteTests
    {
        [TestMethod]
        [ExpectedException(typeof(EventbriteException))] // If the events we're using have expired
        public void ShouldRetrieveEventListForUserEmail()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz");
            
            var list = Eventbrite.GetUserEventList("web.application.toolkits2@hotmail.com");

            Assert.IsTrue(list.Count() > 0);
        }

        [TestMethod]
        public void ShouldRetrieveEventListForUserKey()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", userKey: "12869765797332783553");
            
            var list = Eventbrite.GetUserEventList();

            Assert.IsTrue(list.Count() > 0);
        }

        [TestMethod]
        public void ShouldRetrieveEventListForUserNameAndPassword()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", user: "web.application.toolkits1@hotmail.com", password: "Passw0rd!");
            
            var list = Eventbrite.GetUserEventList();

            Assert.IsTrue(list.Count() > 0);
        }

        [TestMethod]
        [ExpectedException(typeof(EventbriteException))] // If the events we're using have expired
        public void ShouldCreateNewTicket()
        {            
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", userKey: "12869765797332783553");

            var process = Eventbrite.CreateNewTicket(952327437, "My Test Ticket", 100, 10);

            Assert.IsNotNull(process);
            String.Equals(process.Status, "ok", StringComparison.OrdinalIgnoreCase);
        }

        [TestMethod]
        public void ShouldCreateNewEvent()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", userKey: "12869765797332783553");

            var startDate = DateTime.UtcNow.AddDays(1).ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);
            var endDate = DateTime.UtcNow.AddDays(2).ToString("yyyy-MM-dd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture);

            var process = Eventbrite.CreateNewEvent("My Test Event", startDate, endDate, "GMT+01", 667738679, 611185);

            Assert.IsNotNull(process);
            String.Equals(process.Status, "ok", StringComparison.OrdinalIgnoreCase);
        }

        [TestMethod]
        public void ShouldGetUserInfo()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", userKey: "12869765797332783553");

            var user = Eventbrite.GetUserInfo();

            Assert.IsNotNull(user);
            String.Equals(Eventbrite.UserKey, user.UserKey);
        }

        [TestMethod]
        public void ShouldConvertEventStartDateToUtc()
        {
            var eventItem = new Event { StartDate = "2010-10-15 14:30:00", Timezone = "US/Pacific" };

            Assert.AreEqual("2010-10-15 22:30:00", eventItem.StartDateUtc.ToString("yyyy-MM-dd HH:mm:ss"));
        }

        [TestMethod]
        public void ShouldRetrieveEvent()
        {
            Eventbrite.Initialize(appKey: "OTY1Y2NlY2EwZmQz", userKey: "12869765797332783553");

            var eventbriteEvent = Eventbrite.GetEvent(952327437);

            Assert.IsNotNull(eventbriteEvent);
            Assert.IsNotNull(eventbriteEvent.Title);
        }
    }
}
